package com.linfeng.common.response;

public enum ApiCode {

    /**
     * 操作成功
     **/
//    SUCCESS(200, "操作成功"),
    /**
     * 非法访问
     **/
    UNAUTHORIZED(401, "非法访问"),
    /**
     * 没有权限
     **/
    NOT_PERMISSION(403, "没有权限"),
    /**
     * 你请求的资源不存在
     **/
    NOT_FOUND(404, "你请求的资源不存在"),
    /**
     * 操作失败
     **/
    FAIL(500, "操作失败"),
    /**
     * 登录失败
     **/
    LOGIN_EXCEPTION(4000, "登录失败"),
    /**
     * 系统异常
     **/
    SYSTEM_EXCEPTION(5000, "系统异常"),
    /**
     * 请求参数校验异常
     **/
    PARAMETER_EXCEPTION(5001, "请求参数校验异常"),
    /**
     * 请求参数解析异常
     **/
    PARAMETER_PARSE_EXCEPTION(5002, "请求参数解析异常"),
    /**
     * HTTP内容类型异常
     **/
    HTTP_MEDIA_TYPE_EXCEPTION(5003, "HTTP内容类型异常"),
    /**
     * 系统处理异常
     **/
    YSHOP_SYSTEM_EXCEPTION(5100, "系统处理异常"),
    /**
     * 业务处理异常
     **/
    BUSINESS_EXCEPTION(5101, "业务处理异常"),
    /**
     * 数据库处理异常
     **/
    DAO_EXCEPTION(5102, "数据库处理异常"),
    /**
     * 验证码校验异常
     **/
    VERIFICATION_CODE_EXCEPTION(5103, "验证码校验异常"),
    /**
     * 登录授权异常
     **/
    AUTHENTICATION_EXCEPTION(5104, "登录授权异常"),
    /**
     * 没有访问权限
     **/
    UNAUTHENTICATED_EXCEPTION(5105, "没有访问权限"),
    /**
     * 没有访问权限
     **/
    UNAUTHORIZED_EXCEPTION(5106, "没有访问权限"),
    /**
     * JWT Token解析异常
     **/
    JWTDECODE_EXCEPTION(5107, "Token解析异常"),

    HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION(5108, "METHOD NOT SUPPORTED"),


   // ----------------------------------
   //成功...
   LOGIN_SUCCESS(100,"登陆成功"),
    LOGOUT_SUCCESS(106,"登出成功"),

    //失败
    EMPTY(903,"无"),
    TOO_FAST(911,"访问过快"),
    LOGIN_ERROR(926,"登陆失败"),
    INTERFACE_CLOSE(938,"访问失败，接口已被关闭！"),
    VERIFICATION_FAILED(940, "验证失败，没有足够的权限进行访问"),
    HTTP_REQUEST_METHOD_NOT_SUPPORTED(945, "请求错误，未找到指定资源"),
    SUBMISSION_AGREEMENT_ERROR(960, "提交协议不合法"),
    CONTENT_IS_TOO_LARGE(970, "提交内容过大"),
    UNKNOWN(980, "发生了一个未知错误"),

    //基础
    QUERY_SUCCESS(9,"查询成功"),
    SUCCESS(10,"操作成功"),
    ERROR(11,"操作失败"),
    QUERY_ERROR(13,"查询失败"),
    UNKNOWN_ERROR(14,"不好意思，发生了未知错误！"),
    PARAMETER_ERROR(15,"提交参数错误，请仔细检查提交参数！"),
    ;

    private final int code;
    private final String message;

    ApiCode(final int code, final String message) {
        this.code = code;
        this.message = message;
    }

    public static ApiCode getApiCode(int code) {
        ApiCode[] ecs = ApiCode.values();
        for (ApiCode ec : ecs) {
            if (ec.getCode() == code) {
                return ec;
            }
        }
        return SUCCESS;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

}
